package de.derhess.projects.air_flashToMaxMSP
{
	import com.bit101.components.TextArea;
	import com.demonsters.debugger.MonsterDebugger;
	
	import flash.display.Sprite;
	
	import org.tuio.osc.IOSCListener;
	import org.tuio.osc.OSCMessage;

	public class SimpleOSCListener extends Sprite implements IOSCListener
	{
		//--------------------------------------------------------------------------
		//
		//  Class variables
		//
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//
		//  Variables
		//
		//--------------------------------------------------------------------------
		private var myValue:Number = 0;
		private var myValue2:Number = 0;
		//--------------------------------------------------------------------------
		//
		//  Initialization
		//
		//--------------------------------------------------------------------------
		public function SimpleOSCListener()
		{
			
		}
		//--------------------------------------------------------------------------
		//
		//  Properties
		//
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//
		//  Additional getters and setters
		//
		//--------------------------------------------------------------------------
		private var _receiverText:TextArea;
		
		public function set receiverText(text:TextArea):void
		{
			_receiverText = text;
		}
		
		public function get receiverText():TextArea
		{
			return _receiverText;
		}
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//
		//  API
		//
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//
		//  Eventhandling
		//
		//--------------------------------------------------------------------------
		public function acceptOSCMessage(oscmsg:OSCMessage):void
		{
			myValue = oscmsg.arguments[0];
			myValue2 = oscmsg.arguments[1];
			
			//dispatchEvent(new Event(“MESSAGE”))
			
			
			
			MonsterDebugger.trace(this,"-- Message End --");
			MonsterDebugger.trace(this,"");
			MonsterDebugger.inspect(oscmsg);
			
			// Trace the OSC outputs
			if(receiverText) {
				MonsterDebugger.trace(this,"-- Message Start --");
				MonsterDebugger.trace(this,"adress: " + oscmsg.address + "\n");
				//MonsterDebugger.trace(this,"header: " + oscmsg.getPacketInfo() + "\n");
				
				receiverText.text += "Message start<br>   OSC Address: " + oscmsg.address + "<br>   OSC Arguments:<br>";
				var valString:String = "";
				for(var i:int = 0; i < oscmsg.arguments.length; i++)
				{
					valString = "value  "+ i + ": " + oscmsg.arguments[i].toString();
					MonsterDebugger.trace(this,valString)
					receiverText.text += "      " + valString + "<br>";
				}
				receiverText.text += "Message end";
				receiverText.text += "<br><br>  --------------------------------------------------------<br><br>";
			}
		}
		//--------------------------------------------------------------------------
		//
		//  Broadcasting
		//
		//--------------------------------------------------------------------------
	}
}